<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Model extends Controller {
    
    //保存
    public function action_saveInfo(){

        $id=$this->request->post('model_id');

        $pid=$this->request->post('model_pid');

        $caption=$this->request->post('caption');

        $url=$this->request->post('url');

        $sort=$this->request->post('sort');

        $remark=$this->request->post('remark');

        $model=new Model_Admin_SysModel();

        echo $model->saveInfo($id,$pid,$caption,$url,$sort,$remark);
    }
    //删除
    public function action_deleteInfo(){

        $id=$this->request->post('id');

        $model=new Model_Admin_Common();

        echo $model->deleteInfo("sysmodel",$id);
    }
    //根据id加载
    public function action_loadInfoById(){

        $id=$this->request->post('id');

        $sql="select t.sysmodelid model_id,pid model_pid,t.caption,t.url,t.sort,t.remark
              from sysmodel t
              where t.sysmodelid='$id'
              limit 1";

        $model=new Model_Admin_Common();

        echo $model->loadInfoById($sql);
    }
    public function action_loadInfo(){

        $sql="select t.sysmodelid id,t.caption
              from sysmodel t
              where t.isdeleted<>'1'";

        $data=DB::query(Database::SELECT,$sql)->execute()->as_array();

        echo json_encode(array('list'=>$data));
    }
    public function action_setParent(){

        $id=$this->request->post('m_id');

        $pid=$this->request->post('m_pid');

        try {

            $total_rows=DB::update('sysmodel')->set(array('pid'=>$pid))
                ->where('sysmodelid','=',$id)->execute();

            Database::instance()->commit();

            echo json_encode(array("info"=>"success"));
        }
        catch (Exception $e) {

            Database::instance()->rollback();
            
            echo json_encode(array("info"=>"服务器错误，保存失败，请联系管理员或者重试"));
        }
    }
}
?>